//
//  SelectEmployeeCell.swift
//  Employee
//
//  Created by swordjoy on 2017/3/29.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import UIKit

class SelectEmployeeCell: UITableViewCell {
  static var identifier = "SelectEmployeeCell.swordjoy"
  
  static var height: CGFloat = 85
  
  var model: ChatUser? {
    
    didSet {
      
      guard let temp = model else { return }
      
      headIconImageV.setImage(with: temp.headIconUrl, placeholder: GlobalConfig.DefaultHeadIconImage)
      nickNameLabel.text = temp.nickname
      phoneNumberLabel.text = temp.phoneNumber
      departmentLabel.text = temp.department
      
    }
    
  }
  
  fileprivate var contentV: UIView!
  
  fileprivate var selectImageV: UIImageView!
  fileprivate var headIconImageV: UIImageView!
  fileprivate var nickNameLabel: UILabel!
  fileprivate var phoneNumberLabel: UILabel!
  fileprivate var departmentLabel: UILabel!
  
  // MARK: - life cycle
  override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    backgroundColor = UIColor.clear
    create()
  }
  
  required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
  
  override func setSelected(_ selected: Bool, animated: Bool) {
    
    if selected {
      selectImageV.image = UIImage(named: "show-list-radio-icon-selected")
    } else {
      selectImageV.image = UIImage(named: "show-list-radio-icon")
    }
    
  }
  
}

// MARK: - fileprivate

extension SelectEmployeeCell {
  fileprivate func create() {
    contentV = UIView()
    contentView.addSubview(contentV)
    contentV.backgroundColor = UIColor.white
    contentV.snp.makeConstraints { (make) in
      make.left.equalTo(10)
      make.top.equalToSuperview()
      make.right.equalTo(-10)
      make.bottom.equalTo(-5)
    }
    contentV.layer.cornerRadius = 4
    contentV.clipsToBounds = true
    
    selectImageV = UIImageView()
    contentV.addSubview(selectImageV)
    selectImageV.image = UIImage(named: "show-list-radio-icon")
    selectImageV.snp.makeConstraints { (make) in
      make.centerY.equalToSuperview()
      make.left.equalTo(15)
      make.height.width.equalTo(22)
    }
    
    headIconImageV = UIImageView()
    contentV.addSubview(headIconImageV)
    headIconImageV.image = GlobalConfig.DefaultHeadIconImage
    headIconImageV.snp.makeConstraints { (make) in
      make.height.width.equalTo(50)
      make.centerY.equalToSuperview()
      make.left.equalTo(selectImageV.snp.right).offset(15)
    }
    
    nickNameLabel = UILabel()
    contentV.addSubview(nickNameLabel)
    nickNameLabel.font = GlobalConfig.system16Font
    nickNameLabel.textColor = GlobalConfig.TextDeepColor
    nickNameLabel.snp.makeConstraints { (make) in
      make.left.equalTo(headIconImageV.snp.right).offset(12)
      make.top.equalTo(19)
    }
    
    phoneNumberLabel = UILabel()
    contentV.addSubview(phoneNumberLabel)
    phoneNumberLabel.font = GlobalConfig.system14Font
    phoneNumberLabel.textColor = GlobalConfig.TextDeepColor
    phoneNumberLabel.snp.makeConstraints { (make) in
      make.left.equalTo(headIconImageV.snp.right).offset(12)
      make.top.equalTo(nickNameLabel.snp.bottom).offset(12)
    }
    
    departmentLabel = UILabel()
    contentV.addSubview(departmentLabel)
    departmentLabel.font = GlobalConfig.system12Font
    departmentLabel.textColor = GlobalConfig.TextLightColor
    departmentLabel.snp.makeConstraints { (make) in
      make.centerY.equalTo(nickNameLabel.snp.centerY)
      make.right.equalTo(-15)
    }
  }
}
